import request from '@/utils/request';
import { download, toFormData, checkDownloadRes } from '@/utils/common';

/**
 * 分页查询其他费用流水账查询
 */
export async function pageMesFinanceOtherExpensess(params) {
  const res = await request.get('/mes/mesFinanceOtherExpenses/list', { params });
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 查询全部其他费用流水账查询
 */
export async function listMesFinanceOtherExpensess(params) {
  const res = await request.get('/mes/mesFinanceOtherExpenses/list', { params });
  if (res.data.code === 200) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 根据id查询其他费用流水账查询
 */
export async function getMesFinanceOtherExpenses(id) {
  const res = await request.get('/mes/mesFinanceOtherExpenses/' + id);
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 添加其他费用流水账查询
 */
export async function addMesFinanceOtherExpenses(data) {
  const res = await request.post('/mes/mesFinanceOtherExpenses', data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 修改其他费用流水账查询
 */
export async function updateMesFinanceOtherExpenses(data) {
  const res = await request.put('/mes/mesFinanceOtherExpenses', data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 删除其他费用流水账查询
 */
export async function removeMesFinanceOtherExpenses(id) {
  const res = await request.delete('/mes/mesFinanceOtherExpenses/' + id);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 批量删除其他费用流水账查询
 */
export async function removeMesFinanceOtherExpensess(ids) {
  const res = await request.delete('/mes/mesFinanceOtherExpenses/' + ids.join());
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 导出其他费用流水账查询
 */
export async function exportMesFinanceOtherExpensess(params) {
  const res = await request({
    url: '/mes/mesFinanceOtherExpenses/export',
    method: 'POST',
    data: toFormData(params),
    responseType: 'blob'
  });
  await checkDownloadRes(res);
  download(res.data, `mesFinanceOtherExpenses_${Date.now()}.xlsx`);
}
